package com.sixbing.demo;

import android.view.View;
import android.widget.TextView;

import com.sixbing.demo.base.BaseActivity;
import com.company.module.net.bean.BaseBean;
import com.sixbing.demo.bean.AppVersionNetBean;
import com.sixbing.demo.contract.AppHomeView;
import com.sixbing.demo.presenter.AppPresenter;



public class MainActivity extends BaseActivity<AppPresenter, BaseBean> implements AppHomeView.checkUpdateView {
    private TextView textView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        if (mPresenter == null) {
            mPresenter = getPresenter();
        }
        mPresenter.attachView(this, mContext);
        textView = findViewById(R.id.result);
        findViewById(R.id.net).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.checkUpdate();
            }
        });
//        List<File> folders = new ArrayList<>();
//        Observable.from(folders)
//                .flatMap(new Func1<File, Observable<File>>() {
//                    @Override
//                    public Observable<File> call(File file) {
//                        return Observable.from(file.listFiles());
//                    }
//                })
//                .filter(new Func1<File, Boolean>() {
//                    @Override
//                    public Boolean call(File file) {
//                        return file.getName().endsWith(".png");
//                    }
//                })
//                .map(new Func1<File, Bitmap>() {
//                    @Override
//                    public Bitmap call(File file) {
//                        return getBitmapFromFile(file);
//                    }
//                })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Action1<Bitmap>() {
//                    @Override
//                    public void call(Bitmap bitmap) {
//                        imageCollectorView.addImage(bitmap);
//                    }
//                });
    }

    @Override
    public void checkUpdateSuccess(BaseBean<AppVersionNetBean> userInfoBean) {
        textView.setText(userInfoBean.getData().getReason());
    }

    @Override
    public void checkUpdateFault(BaseBean<AppVersionNetBean> baseBean) {
        showToast(baseBean.getMsg());
    }
}
